<admintpl file="header" />

<!--必要样式-->
<style type="text/css">
#BgDiv1{background-color:#000; position:absolute; z-index:9999;  display:none;left:0px; top:0px; width:100%; height:100%;opacity: 0.6; filter: alpha(opacity=60);}
.DialogDiv{position:absolute;z-index:99999;}/*配送公告*/
.U-user-login-btn{ display:block; border:none; font-size:1em; color:#efefef; line-height:49px; cursor:pointer; height:53px; font-weight:bold;
border-radius:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
 width:100%; box-shadow: 0 1px 4px #cbcacf, 0 0 40px #cbcacf ;}
 .U-user-login-btn:hover, .U-user-login-btn:active{ display:block; border:none; font-size:1em; color:#efefef; line-height:49px; cursor:pointer; height:53px; font-weight:bold;
border-radius:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
 width:100%; box-shadow: 0 1px 4px #cbcacf, 0 0 40px #cbcacf ;}
.U-user-login-btn2{ display:block; border:none; font-size:1em; color:#efefef; line-height:49px; cursor:pointer; font-weight:bold;
border-radius:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
 width:100%; box-shadow: 0 1px 4px #cbcacf, 0 0 40px #cbcacf ;height:53px;}
.U-guodu-box { padding:5px 15px;  background:#3c3c3f; filter:alpha(opacity=90); -moz-opacity:0.9; -khtml-opacity: 0.9; opacity: 0.9;  min-heigh:200px; border-radius:10px;}
.U-guodu-box div{ color:#fff; line-height:20px; font-size:15px; margin:0px auto; height:100%; padding-top:10%; padding-bottom:10%;}

</style>

</head>
<body class="J_scroll_fixed">
	<div id="BgDiv1"></div>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:U('Subpackage/qudaoindex')}">一键分包</a></li>
			<if condition = "$cpscheck eq 0">
			<li><a href="{:U('Subpackage/addagent')}" target="_self">添加渠道</a></li>
			</if>
		</ul>

		<form id="fm" class="well form-search" method="post" action="{:U('Subpackage/qudaoindex')}">
			
			<div class="search_type cc mb10">
				<div class="mb10">
					<span class="mr20">
					        游戏： 
						<select class="select_2" name="app_id" id="selected_id">
							<foreach name="games"  key="k" item="vo">
								<php>$g_select=$k==$app_id ?"selected":"";</php>
								<option value="{$k}"{$g_select}>{$vo}</option>
							</foreach>
						</select>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;					
						渠道账号： 
						<select class="select_2" name="agent_id" id="selected_id">
							<foreach name="agents"  key="k" item="vo">
								<php>$a_select=$k==$agent_id ?"selected":"";</php>
								<option value="{$k}"{$a_select}>{$vo}</option>
							</foreach>
						</select>
						&nbsp;&nbsp;
						<button type="submit" name='search' id='search' class="btn btn-warning"/>搜索</button>
						<br>
						<br>
						<if condition = "$cpscheck eq 0">
						分成比例： 
						<input type="text" name="rate"  value="" placeholder="分成比例...">
						&nbsp;&nbsp;
						cpa价格： 
						<input type="text" name="cpa_price" value="" placeholder="CPA价格...">
						&nbsp;&nbsp;
						</if>
						<input type="hidden" name="bagurl" id="bagurl" value="{:U('Subpackage/subpackage')}">
						<input type="button" name='action' id='action' class="btn btn-primary" value="一键分包" />
						
						<div class="DialogDiv"  style="display:none; ">
								<div class="U-guodu-box">
								<div>
								<table width="100%" cellpadding="0" cellspacing="0" border="0" >
									<tr><td  align="center"><img src="__PUBLIC__/images/load.gif"></td></tr>
									<tr><td  valign="middle" align="center" >提交中,提交完成前请勿做其它操作！</td></tr>
								</table>
								</div>
							</div>
						</div>
					</span>
				</div>
			</div>
		</form>
		<form class="js-ajax-form" action="" method="post">
		<input name="adminsite" type="hidden"  id="adminsite" value="{:U('Subpackage/ajaxGetagent')}">
			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>
						<th>游戏渠道号</th>
						<th>渠道账号</th>
						<th>渠道名称</th>
						<th>游戏</th>
						<th>渠道类型</th>						
						<th>cpa价格</th>
						<th>分成比例</th>
						<th>时间</th>
						<th>下载地址</th>
						<th width="100">管理操作</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="subagents" item="vo">
						<tr>
							<td>{$vo.agentgame}</td>
							<td>{$agents[$vo[agent_id]]}</td>
							<td>{$vo['user_nicename']}</td>
							<td>{$games[$vo['app_id']]}</td>
							<td>{$roles[$vo['user_type']]}</td>
							<td>{$vo.cpa_price}</td>
							<td>{$vo.agent_rate}</td>
							<td>
								<notempty name="vo['create_time']">
											{$vo.create_time|date='Y-m-d H:i:s',###}
								</notempty>
							</td>
							<td>
							    <notempty name="vo['url']">
										{:DOWNSITE}/sdkgame/{$vo.url}
								<else />
										还没有母包
								</notempty>
							</td>
							<td>
								<a href="{:U('Subpackage/updatepackage',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="确定更新吗？">更新 </a>
								<if condition = "$cpscheck eq 0">
								<a href="{:U('Subpackage/delagentgame',array('id'=>$vo['id']))}" class="js-ajax-delete"> | 删除</a>
								</if>
							</td>
						</tr>
					</foreach>
				</tbody>
				
			</table>
			<div class="pagination">{$Page}</div>

		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script src="__PUBLIC__/js/jquery.form.js"></script>

	<script>
		$(document).ready(function () {
			$("#action").click(function () {
				$("#BgDiv1").css({
				display: "block", height: $(document).height() });
				var yscroll = document.documentElement.scrollTop;
				var screenx=$(window).width();
				var screeny=$(window).height();
				$(".DialogDiv").css("display", "block");
				 $(".DialogDiv").css("top",yscroll+"px");
				 var DialogDiv_width=$(".DialogDiv").width();
				 var DialogDiv_height=$(".DialogDiv").height();
				  $(".DialogDiv").css("left",(screenx/2-DialogDiv_width/2)+"px")
				 $(".DialogDiv").css("top",(screeny/2-DialogDiv_height/2)+"px")
				 $("body").css("overflow","hidden");

				var bagurl = $("#bagurl").val();

				var options = {
					url: bagurl,
					type: 'post',
					dataType: 'json',
					data: $("#fm").serialize(),
					success:function(data){
						$("#BgDiv1").css({ 
						display: "none", height: $(document).height() });
						$(".DialogDiv").css("display", "none");
						 $("body").css("overflow","visible");

						if (data.success){
							alert(data.msg);
							window.location.reload();//刷新当前页面.
						} else {
							alert(data.msg);
							window.location.reload();//刷新当前页面.
						}
					}
				};
				$.ajax(options);
				return false;
			});
			
			$("#agent_type").bind("change",function(){
				var agent_type = $("#agent_type").val();
				if (agent_type == "1") {
					$("#agent_ida").show();	
					$("#agent_idb").hide();
				} else {
					$("#agent_idb").show();	
					$("#agent_ida").hide();
				}	
			});

			Wind.use('artDialog', function () {
				$('.J_ajax_updatebag').on('click', function (e) {
					e.preventDefault();
					var $_this = this,
						$this = $($_this),
						href = $this.prop('href'),
						msg = $this.data('msg');
					art.dialog({
						title: false,
						icon: 'question',
						content: '确定要更新吗？',
						follow: $_this,
						close: function () {
							$_this.focus();; //关闭时让触发弹窗的元素获取焦点
							return true;
						},
						ok: function () {
							$("#BgDiv1").css({ 
							display: "block", height: $(document).height() });
							var yscroll = document.documentElement.scrollTop;
							var screenx=$(window).width();
							var screeny=$(window).height();
							$(".DialogDiv").css("display", "block");
							 $(".DialogDiv").css("top",yscroll+"px");
							 var DialogDiv_width=$(".DialogDiv").width();
							 var DialogDiv_height=$(".DialogDiv").height();
							  $(".DialogDiv").css("left",(screenx/2-DialogDiv_width/2)+"px")
							 $(".DialogDiv").css("top",(screeny/2-DialogDiv_height/2)+"px")
							 $("body").css("overflow","hidden");

							$.getJSON(href).done(function (data) {
								$("#BgDiv1").css({ 
								display: "none", height: $(document).height() });
								$(".DialogDiv").css("display", "none");
								 $("body").css("overflow","visible");

								if (data.success) {
									alert(data.msg);
									if (data.referer) {
										location.href = data.referer;
									} else {
										reloadPage(window);
									}
								} else {
									//art.dialog.alert(data.info);
									alert(data.info);//暂时处理方案
								}
							});
						},
						cancelVal: '关闭',
						cancel: true
					});
				});

			});

		});
	</script>
</body>
</html>